package edu.msg.hrappy.backend.service.beans;

import edu.msg.hrappy.backend.model.Candidate;
import edu.msg.hrappy.backend.repository.CandidateRepository;
import edu.msg.hrappy.backend.repository.exception.RepositoryException;
import edu.msg.hrappy.backend.service.CandidateService;
import edu.msg.hrappy.backend.service.exception.ServiceException;
import java.util.Collections;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

@Stateless
public class CandidateServiceBean implements CandidateService {

    @EJB
    private CandidateRepository candidateDAO;

    @Override
    public void insert(Candidate obj) {

        try {
            candidateDAO.insert(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public void update(Candidate obj) {
        try {
            candidateDAO.update(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public void delete(Candidate obj) {
        try {
            candidateDAO.delete(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public List<Candidate> getAll() {
        List<Candidate> all = Collections.emptyList();
        try {
            all = candidateDAO.getAll();
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }
        return all;
    }

    @Override
    public Candidate getById(Long id) {
        Candidate one;
        try {
            one = candidateDAO.getById(id);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }
        return one;
    }

}
